# 读取txt文件

# 绝对路径
# path = r"C:\Users\shy\Desktop\课件\单词表.txt"  #  raw 生
# 也可以是相对路径
# path = r'单词表_在同一文件夹下.txt' #  raw 生
# path = r'file/单词表_在同一文件夹下.txt' #  raw 生
#
# f = open(path, 'r')  # 读取，拿到文件句柄
#
# for line in f:
#     # print(line, end='')  # 打印每一行
#     print(line.rstrip())  # 会把右边的换行符去掉，换行符也是空白符号
#
# f.close()  # 记得关闭文件

# with open 用法
#
# path = r'file/单词表_在同一文件夹下.txt' #  raw 生
#
# # 读取中文、日语，都要加encoding  编码方式
# with open(path, 'r', encoding='utf-8') as f:
#     for line in f:
#         # print(line, end='')  # 打印每一行
#         print(line.rstrip())  # 会把右边的换行符去掉，换行符也是空白符号
#

# import csv
#
# path = r'file/my2222.csv'  # raw 生
# path = r'009_列表.py'  # raw 生
#
# # 读取中文、日语，都要加encoding  编码方式
# with open(path, 'r', encoding='utf-8') as f:
#     for line in f:
#         # print(line, end='')  # 打印每一行
#         print(line.rstrip())  # 会把右边的换行符去掉，换行符也是空白符号
#
# from PIL import Image
#
#
# im_path = r"C:\Users\shy\Desktop\课件\周杰伦.jpg"
#
# img = Image.open(im_path)  # 底层用open
# print(img.size)
# print(img.size[0])  # 宽度
# print(img.size[1])  # 高度
# # img.show()
#
# im = img.convert("L")  # 将图片弄成灰色
# im.save('file/灰色.png')  # 把这灰色图片保存成，file文件夹下的灰色.jpg


# 有一个文件夹下，好多个png图片，你想批量的把他们变成jpg

# from openpyxl import load_workbook
#
# excel_path = r"C:\Users\shy\Desktop\课件\录入技巧.xlsx"
# im_path = r"C:\Users\shy\Desktop\课件\周杰伦.jpg"
# #
# # wb = load_workbook(excel_path)  # 打开工作簿
# #
# # for ws in wb.worksheets:
# #     print(ws.title)
# #     a1 = ws['A1'].value
# #     print(a1)
#
# with open(im_path, 'rb') as f:
#     print(f.read(1000))

# w 对应的 write  覆盖写入
# with open('data.txt', 'w', encoding='utf-8') as f:
#     f.write('第二次\n王鑫2\n非常好~\n')

# # 复习r read 读取
# with open('data.txt', 'r', encoding='utf-8') as file:
#     for line in file:
#         print(line.rstrip())



# a append 追加写入
# lines = []
# for i in range(10):
#     lines.append(f'{i}')
# print(lines)
#
# with open('data.txt', 'a', encoding='utf-8') as f:
#     # f.write('追加呢\n')  # 追加
#     # help(f.writelines)
#     f.writelines('\n'.join(lines))


f = open('data.txt', 'r', encoding='utf-8')
f_content = f.read()   # f.read 读取一个txt文件， 返回一个字符串
# print(f_content)
# f_lines = f.readlines()
# print(f_lines)
f.close()




